package com.odianyun.hello.web.controller;

import com.github.pagehelper.Page;
import com.odianyun.db.mybatis.Filter;
import com.odianyun.db.query.PageVO;
import com.odianyun.hello.model.DTO.SoItemDTO;
import com.odianyun.hello.model.PO.CodePO;
import com.odianyun.hello.model.PO.SoPO;
import com.odianyun.hello.model.VO.CodeVO;
import com.odianyun.hello.model.VO.SoVO;
import com.odianyun.hello.service.SoService;
import com.odianyun.project.model.vo.ListResult;
import com.odianyun.project.model.vo.ObjectResult;
import com.odianyun.project.model.vo.PageResult;
import com.odianyun.project.model.vo.Result;
import com.odianyun.project.query.PageQueryArgs;
import com.odianyun.project.query.QueryArgs;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.odianyun.hello.model.DTO.SoDTO;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
public class SoController extends AbstractSoController<SoDTO> {

    @Resource
    private SoService soService;

    @ApiOperation("多条件分页查询")
    @PostMapping("ListPageByMore")
    public PageResult<SoVO> ListPageByMore(@RequestBody PageQueryArgs args ,String[] selectSoItemFiled){
        PageVO<SoVO> so = soService.ListPageByMore(args, selectSoItemFiled);
        return PageResult.ok(so);
    }

    @ApiOperation("多条件查询")
    @PostMapping("getStatus")
    public Result getStatus(@RequestBody QueryArgs args){
        Map<String,Long> soList = soService.getStatus(args);
        return ObjectResult.ok(soList);
    }

    @ApiOperation("订单状态更新")
    @PostMapping("updateStatus")
    public Result updateStatus(String orderCode){
        soService.updateStatus(orderCode);
        return ObjectResult.OK;
    }

    @ApiOperation("订单状态更新")
    @PostMapping("getCountByStatus")
    public ListResult<Map<String, Object>> getCountByStatus(@RequestBody QueryArgs args){
        List<Map<String, Object>> list = service.getCountByStatus(args);
        return ListResult.ok(list);
    }


}
